home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: lewkbj@ix.netcom.com(leonel wizel )
- Newsgroups: comp.lang.c++
- Subject: help with homework
- Date: 20 Apr 1996 03:30:46 GMT
- Organization: Netcom
- Message-ID: <4l9lp6$cr1@reader2.ix.netcom.com>
- NNTP-Posting-Host: ix-nyc17-20.ix.netcom.com
- X-NETCOM-Date: Fri Apr 19 8:30:46 PM PDT 1996
-
- To all of you experienced programmers. I have some problems
- understanding the object concept and that is the reason that I need
- some help from you all experienced programmers.
-
-
- the problem that I have no I have to improve a class called Time
-
-
- I have to write a driver program that tests the tick member function in
- a loop that prints the time in standard format during each iteration of
- the loop to illustrate that the tick member function works correctly.
- I have
-
- to be sure to test the following cases:
-
- incrememting into the next minute
- incrementing into the next hour.
- incrementing into the next day.(i.e., 11:59:59 PM to 12:00:00 AM).
-
- then I have to modify and add a different class or functions to perfor
- error checking on the initializer values for data members month, day,
- and year. and provide a member function nextDay to increment day by
- one. The Da
-
- te object should always remain ina consisten state. and write a
- driver program that tests the nextday function in a loop that prints
- the date during each iteration of the loop to illustrate that the next
- day function wo
-
- rks correctly.
-
- incrementing into the next month.
- incrementing into the next year.
-
- then modified Time and modified Date into one class called DateAndTime.
- modified the tick functio to call the next day function if the time is
- incremented into the next day. modified function printStandard and
- PrintMilit
-
- ary to output the date in addition to the time, and write a driver to
- test the new class DateAndTime; to test incrementing the time into the
- next day.
-
- then modify the set function in the program to return appropiate
- error values in an attempt is made to set a data member of an object of
- class Time to an invalid value.
-
-
- Thank you very much for your cooperation.
-
- This is that I have written so far.
-
- File no 1.
-
-
- //times3.h
-
- #ifndef TIME3_H
- #define TIME3_H
-
- class Time {
- public:
- Time(int = 0, int = 0, int = 0); // constructor
-
- //set functions
-
- void setTime(int, int, int); //set hour, minute, second
- void setHour(int);
- void setMinute(int);
- void setSecond(int);
-
- //get functions
-
- int getHour(); //return hour
- int getMinute(); //return minute
- int getSecond(); //return second
-
- void tick_increment(); // increments time
- void printMilitary(); //output military time
- void printStandar(); //output standard time
-
- private:
- int hour;
- int minute;
- int second;
- };
-
- #endif
-
-
- File No 2.
-
- //this is file time3.cpp
- #include "time3.h"
- #include <iostream.h>
-
-
- //constructor function.
-
- Time::Time(int hr, int min, int sec) {setTime (hr, min, sec); }
-
- void Time::setTime(int h, int m, int s)
- {
- hour = (h >= 0 && h < 24) ? h : 0; //check for negative values
- minute = (m >= 0 && m < 60) ? m : 0;
- second = (s >= 0 && s < 60) ? s : 0;
- }
- void Time::setMinute(int m)
-
- {minute = (m >= 60) ? m : 0;}
-
- void Time::setSecond(int s)
-
- {second = (s >= 60) ? s : 0;}
-
- int Time::getHour() {return hour; }
-
- int Time::getMinute() { return minute;}
-
- int Time::getSecond() { return second; }
-
- void Time::tick_increment()
- {
- if(second == 60)
- {
- second = 0;
- minute++;
- }
- second++;
- if (second == 60)
- {
- second = 0;
- minute++;
- }
- if(minute == 60)
- {
- minute = 0;
- hour++;
- }
- }
-
- void Time::printMilitary()
- {
- cout << (hour < 10 ? "0" : "") << hour << ":"
- << (minute < 10 ? "0" : "") << minute <<":"
- << (second < 10 ? "0" : "") << second;
- }
- void Time::printStandard()
- {
- cout << ((hour == 0 || hour == 12) ? 12 : hour % 12) << ":"
- << (minute < 10 ? "0" : "") << minute << ":"
- << (second < 10 ? "0" : "") << second
- << (hour < 12 ? " AM" : " PM");
- }
-
-
- file No 3
-
- #include <iostream.h>
- #include "time3.h"
- #include "time3.cpp"
-
- main()
- {
- Time t;
-
- t.setTime(4, 00, 31);
-
- for(long int i = 1; i <= 2; i++)
- {
- cout << "Hour " << t.getHour() << endl << endl;
- cout << "Minute " <<t.getMinute() << endl;
- cout << "Second" << t.getSecond() << endl << endl;
- cout << "the initial time before incrementing is: " << endl;
-
- t.printStandard();
- t.printMilitary();
-
- t.tick_increment();
-
- cout << " Hour " << t.getHour() << endl << endl;
- cout << " Minute " << t.getMinute() << endl;
- cout << " Second " << t.getSecond() << endl << endl;
-
- cout << "The time after incrementing is: " << endl;
-
- t.printStandard();
- t.PrintMilitary();
- }
- return 0;
- }
-
-
-
- This are the files that I am working on it; but I encounter some
- difficulties improving all the classes to work respectively with the
- specifications all this code is preliminary.
-
-
-
- thank you very much to all of you for your suggestions.
-
-